<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-cn" xml:lang="zh-cn">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title><?=isset($pagetitle)?$pagetitle.' - ':''?> 网站后台管理系统</title>
  <?=HTML::style ('styles/admin/stylesheet.css')?>
  <?=HTML::style ('scripts/admin/jquery/ui/themes/ui-lightness/jquery-ui-1.8.16.custom.css')?>
  <?=HTML::script('scripts/admin/jquery/jquery-1.7.2.min.js')?>
  <?=HTML::script('scripts/admin/jquery/ui/jquery-ui-1.8.16.custom.min.js')?>
  <?=HTML::script('scripts/admin/jquery/ui/i18n/jquery.ui.datepicker-zh-CN.js')?>
  <?=HTML::script('scripts/admin/jquery/ui/external/jquery.bgiframe-2.1.2.js')?>
  <?=HTML::script('scripts/admin/jquery/tabs.js')?>
  <?=HTML::script('scripts/admin/jquery/superfish/js/superfish.js')?>
  <?=HTML::script('scripts/admin/jquery/jquery.form.js')?>
</head>
<body>
<div id="container">
<div id="header">
  <div class="div1">
    <div class="div2"><img src="<?=URL::base()?>images/admin/logo.png" title="网站首页" onclick="location='<?=URL::site()?>'" /></div>
    <? if ($manager->is_logined()) { ?>
    <div class="div3"><img src="<?=URL::base()?>images/admin/lock.png" alt="" style="position: relative; top: 3px;" />&nbsp;<?=$manager->nickname?>，您已登录为<?=$manager->role_name?></div>
    <? } ?>
  </div>
  <? if ($manager->is_logined()) { ?>
  <div id="menu">
    <ul class="left" style="display: none;">
      <!--li id="dashboard"><a href="<?=URL::site('admin')?>" class="top">管理首页</a></li-->
      <?=_show_menu()?>
    </ul>
    <ul class="right">
      <li id="store"><a class="top" href="<?=URL::site('admin/account/logout')?>">退出登录</a></li>
    </ul>
  </div>
  <? } ?>
</div>
<?
function _show_menu() {
    $menus = Config::get('menu');
    $html = array();
    foreach ($menus as $key => $val) {
        if ( ! _is_allow($val)) {
            continue;
        }
        $html[] = '<li id="'.$key.'"><a class="top">'.__('admin.menu.'.$key).'</a>';
        $html[] = _show_menu_option($val);
        $html[] = '</li>';
    }
    return implode("\n", $html);
}
function _show_menu_option(array $option) {
    $html[] = '<ul>';
    foreach ($option as $key => $val) {
        if ( ! _is_allow($val)) {
            continue;
        }
        if (isset($val['url'])) {
            $html[] = '<li><a href="'.$val['url'].'" target="'.Arr::get($val, 'target', '_self').'">'.$key.'</a></li>';
        } else {
            $html[] = '<li><a class="parent">'.$key.'</a>';
            $html[] = _show_menu_option($val);
            $html[] = '</li>';
        }
    }
    $html[] = '</ul>';
    return implode("\n", $html);
}
function _is_allow(array $data) {
    if (isset($data['url'])) {
        return isset($data['privs']) ? Manager::instance()->has_allow($data['privs']) : TRUE;
    }
    foreach ($data as $key => $val)
    {
        if (is_array($val)) {
            $is_allow = _is_allow($val);
            if ($is_allow) {
                return TRUE;
            }
        }
    }
    return FALSE;
}
?>